﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Diagnostics;
using CommonClass;
using FileLib;

namespace WebAppProject.Service
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“WebAppService”。
    public class WebAppService : IWebAppService
    {
        /// <summary>
        /// 根据项目类别获取更新文件名称列表
        /// </summary>
        /// <param name="projectType">项目类别 ProjectTypeEnum</param>
        /// <returns></returns>
        public string[] GetUpdateFiles(string projectType)
        {
            try
            {
                string dirPath = string.Empty;
                return FileOperation.GetFiles(dirPath);
            }
            catch (System.Exception ex)
            {
#if DEBUG
                Debug.WriteLine(ex.Message);
#endif
                return null;
            }
        }

        /// <summary>
        /// 根据项目类别获取最新版本号
        /// </summary>
        /// <param name="projectType">项目类别 ProjectTypeEnum</param>
        /// <returns></returns>
        public string GetLatestVersion(string projectType)
        {
            try
            {
                ProjectTypeEnum outProjectType;
                if (!Enum.TryParse<ProjectTypeEnum>(projectType, true, out outProjectType))
                    return string.Empty;

                return Utilities.GetLatestVersion(Utilities.GetUpgradePath(projectType));
            }
            catch (System.Exception ex)
            {
#if DEBUG
                Debug.WriteLine(ex.Message);
#endif
                return string.Empty;
            }
        }
    }
}
